import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/net/response/hand_over/hand_over_detail_info.dart';

import '../../a_yyt/models/handover_new_entity.dart';
import '../../net/response/hand_over/hand_over_area_data.dart';

class HandOverModel extends BaseMvvmModel{
  @override
  void onCleared() {
  }


  ///获取交接班列表
  Future<List<HandoverNewInfo>> handOverList(dynamic queryType) async {
    var map = {
      "queryType":queryType,
    };
    var data = await HttpGo.instance.postData(HttpApi.shiftingDutyReport,data: map,options: Options(contentType: Headers.formUrlEncodedContentType));
    if("0"==data['code']){
      var bean = HandoverNewEntity.fromJson(data);
      return bean.data??[];
    }else{
      throw data['msg'];
    }
  }

  Future<List<HandoverNewInfo>> newHandOverList({required dynamic  queryType}) async {
    var map = {
      "queryType":queryType,
    };
    var data = await HttpGo.instance.postData(HttpApi.shiftingDutyReport,data: map,options: Options(contentType: Headers.formUrlEncodedContentType));
    if("0"==data['code']){
      var bean = HandoverNewEntity.fromJson(data);
      return bean.data??[];
    }else{
      throw data['msg'];
    }
  }

  ///获取区域列表
  Future<List<HandOverAreaData>> handOverAreaList(dynamic id) async {
    var map = {
      "id":id
    };
    var data = await HttpGo.instance.postData(HttpApi.handoverRefresh,data: map,options: Options(contentType: Headers.formUrlEncodedContentType));
    if("0"==data['code']){
      return ((data['data']['areas'] as List?)??[]).map((e) => HandOverAreaData.fromJson(e)).toList();
    }else{
      throw data['msg'];
    }
  }

  ///获取交接班详情
  Future<HandOverDetailInfo> handOverDetail({String? reportDate,dynamic dutyType,dynamic areaId,String? startTime,String? endTime}) async {
    var map = {
      "reportDate":reportDate,
      "dutyType":dutyType,
      "areaId":areaId,
      "startTime":startTime,
      "endTime":endTime,
    };
    var data = await HttpGo.instance.postData(HttpApi.shiftingDutyArea,data: map,options: Options(contentType: Headers.formUrlEncodedContentType));
    if("0"==data['code']){
      return HandOverDetailInfo.fromJson(data['data']);
    }else{
      throw data['msg'];
    }
  }

  ///交班总结
  Future<Map> handOverArchive({required dynamic id, dynamic archive = 0,required String summary}) async {
    var map = {
      "id":id,
      "archive":archive,
      "summary":summary,
    };
    var data = await HttpGo.instance.postData(HttpApi.shiftingDutyArchive,data: map,options: Options(contentType: Headers.jsonContentType));
    if("0"==data['code']){
      return data;
    }else{
      throw data['msg'];
    }
  }


}